// 基于准备好的dom，初始化echarts实例
window.onload=function(){


    viewCpu()
  function viewCpu() {
      var dom = document.getElementById("container");
      var myChart = echarts.init(dom);
      var app = {};
      option = null;

      //显示X轴的时间
      var data = [];
      var today=new Date();
      var value =today.getHours()+":"+today.getMinutes()+":"+today.getSeconds();
      data.push(value);

      option = {
          title: {
              text: 'CPU',
              padding: [5, 10, 0, 25,]
          },
          tooltip: {
              trigger: 'axis',
              triggerOn: 'mousemove',
              formatter: function (params) {
                  params = params[0];
                  var date = new Date(params.name);
                  return date.getDate() + '/' + params.value[1];
              },
              backgroundColor: "rgba(92, 172, 238,0.7)",
              axisPointer: {
                  animation: true,
              },
          },
          xAxis: {
              type: 'time',
              name: "time",
              splitLine: {
                  show: false
              },

          },
          yAxis: {
              type: 'value',
              boundaryGap: [0, '100%'],
              name: "百分比",
              splitLine: {
                  show: true
              }
          },
          series: [{
              name: 'CPU',
              type: 'line',
              showSymbol: false,
              hoverAnimation: false,
              data: data
          }]
      };

      app.timeTicket = setInterval(function () {

          for (var i = 0; i < 5; i++) {
              data.shift();
              data.push();
          }

          myChart.setOption({
              series: [{
                  data: data
              }]
          });
      }, 1000);
      ;
      if (option && typeof option === "object") {
          var startTime = +new Date();
          myChart.setOption(option, true);
          var endTime = +new Date();
          var updateTime = endTime - startTime;
          console.log("Time used:", updateTime);
      }
  }
//    ajax请求cpu数据
    function dateshow(){
        $.ajax({
            url:"/jquery/test1.txt",
            async:false
        });
    }
    //ajax请求cpu数据
    dateshow()
    function dateshow(){
        $.ajax({
            url:"http://127.0.0.1:8000/penginecon/1",
            type:"POST",
            async:false,
            success: function(msg){
                var cpudata=eval("("+msg+")")["cpu"]

                console.log(cpudata);
            },
            error: function(e) {
                console.log("发生错误"+e);
            }
        });
    }

}
